use "$project_path/data/4_regdata/regdata", clear
merge m:1 Country Year using "$project_path/data/3_cleaned/outcomes", keep(master match) keepusing(democratization dem_reversal)
egen event_regime_change = rowmax(democratization dem_reversal)

** Appendix Figure C.4(a)

rdrobust event_regime_change runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot event_regime_change runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(0(0.1)0.3, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) legend(off) title("Event probability", size(large) placement(9) span)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_C4a.pdf", as(pdf) name("Graph") replace

** Appendix Figure C.4(b)

rdrobust democratization runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot democratization runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(0(0.1)0.3, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) legend(off) title("Event probability", size(large) placement(9) span)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_C4b.pdf", as(pdf) name("Graph") replace

** Appendix Figure C.4(c)

rdrobust dem_reversal runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot dem_reversal runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(0(0.1)0.3, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) legend(off) title("Event probability", size(large) placement(9) span)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_C4c.pdf", as(pdf) name("Graph") replace

